package transform.app.editors.table.edit;

import model.Relationship;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;

public class ProbRelationshipEditingSupport extends EditingSupport {
	
	private TableViewer viewer;
	
	public ProbRelationshipEditingSupport(TableViewer viewer) {
		super(viewer);
		this.viewer = viewer;
	}

	@Override
	protected CellEditor getCellEditor(Object element) {
		return new TextCellEditor(viewer.getTable());
	}

	@Override
	protected boolean canEdit(Object element) {
		return true;
	}

	@Override
	protected Object getValue(Object element) {
		return String.valueOf(((Relationship)element).getCost());
	}

	@Override
	protected void setValue(Object element, Object value) {
		try {
			Integer.valueOf((String)value);
			((Relationship)element).setCost(Integer.valueOf((String)value).intValue());
		} catch (Exception e) {
			System.out.println("DEBUG: se espera un int");
		}
		
		
		viewer.refresh();
	}
}
